package flexcommon.tests.validators
{
	import flexunit.framework.Assert;
	import flexunit.framework.TestCase;
	
	import flexcommon.validators.RFCEmailValidator;
	
	import mx.events.ValidationResultEvent;

	/**
	 * @private
	 */
	public class TestRFCEmailValidator extends TestCase
	{
		private var val:RFCEmailValidator;
		
		public function TestRFCEmailValidator(methodName:String=null)
		{
			super(methodName);
		}
		
		public override function setUp():void 
		{
	    	val = new RFCEmailValidator();
	    }
		
		public function testValidEmail():void 
		{
	        try {
				var res:ValidationResultEvent = val.validate( "jimmy.hunter@where.com", true );
	        	Assert.assertEquals( "valid", res.type );
	        }
	        catch( e:Error ) {
	        	trace( "testValidEmail >> " + e.getStackTrace() );
	        	fail( "testValidEmail failed: " + e.message );
	        }
	    }	
	    
	    public function testValidEmailWithIP():void 
		{
	        try {
				var res:ValidationResultEvent = val.validate( "jimmy@[192.66.5.5]", true );
	        	Assert.assertEquals( "valid", res.type );
	        }
	        catch( e:Error ) {
	        	trace( "testValidEmailWithIP >> " + e.getStackTrace() );
	        	fail( "testValidEmailWithIP failed: " + e.message );
	        }
	    }
	    
	    public function testBadEmailNoAt():void 
		{
	        try {
				var res:ValidationResultEvent = val.validate( "jimmywhere.com", true );
	        	Assert.assertEquals( "invalid", res.type );
	        }
	        catch( e:Error ) {
	        	trace( "testBadEmailNoAt >> " + e.getStackTrace() );
	        	fail( "testBadEmailNoAt failed: " + e.message );
	        }
	    }
	    
	    public function testBadEmailBadSuffix():void 
		{
	        try {
				var res:ValidationResultEvent = val.validate( "jimmy@where.", true );
	        	Assert.assertEquals( "invalid", res.type );
	        }
	        catch( e:Error ) {
	        	trace( "testBadEmailBadSuffix >> " + e.getStackTrace() );
	        	fail( "testBadEmailBadSuffix failed: " + e.message );
	        }
	    }
	    
	    public function testBadEmailBadSuffix2():void 
		{
	        try {
				var res:ValidationResultEvent = val.validate( "jimmy@wherecom", true );
	        	Assert.assertEquals( "invalid", res.type );
	        }
	        catch( e:Error ) {
	        	trace( "testBadEmailBadSuffix2 >> " + e.getStackTrace() );
	        	fail( "testBadEmailBadSuffix2 failed: " + e.message );
	        }
	    }
	    
	    public function testBadEmailBadChar():void 
		{
	        try {
				var res:ValidationResultEvent = val.validate( "jimmy@whe're.com", true );
	        	Assert.assertEquals( "invalid", res.type );
	        }
	        catch( e:Error ) {
	        	trace( "testBadEmailBadChar >> " + e.getStackTrace() );
	        	fail( "testBadEmailBadChar failed: " + e.message );
	        }
	    }
	    
	    public function testBadEmailBadChar2():void 
		{
	        try {
				var res:ValidationResultEvent = val.validate( "jim[]my@where.com", true );
	        	Assert.assertEquals( "invalid", res.type );
	        }
	        catch( e:Error ) {
	        	trace( "testBadEmailBadChar2 >> " + e.getStackTrace() );
	        	fail( "testBadEmailBadChar2 failed: " + e.message );
	        }
	    }
	}
}